package com.example.base.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.base.entity.Chapter;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface ChapterMapper extends BaseMapper<Chapter> {


    @Select({"<script>" +
            "select chapter.createTime,chapter.createName,chapter.updateTime,chapter.updateName,chapter.delSign," +
            "chapter.status,chapterId,chapterName,chapterNum,chapterSign,chapter.courseId,preChapterId,priority," +
            "resourceUrl,course.courseName " +
            "from chapter left join course " +
            "on chapter.courseId = course.courseId " +
            "where " +
            "chapter.courseId = #{chapter.courseId}" +
            "<when test='chapter.chapterName != null'>" +
            "and chapterName = #{chapter.chapterName} " +
            "</when>" +
            "<when test='chapter.status != null'>" +
            "and chapter.status = #{chapter.status} " +
            "</when>" +
            "limit #{prePage}, #{size}" +
            "</script>"})
    List<Map<String, Object>> selectChapter(Chapter chapter, Integer prePage, Integer size, String courseName);
}
